import 'package:flutter/material.dart';
import 'package:lib_furnace/gt_router.dart';
import 'package:lib_furnace/navigator/gt_native_dialog_helper.dart';

class GTNativeDialogWrap extends StatefulWidget {
  const GTNativeDialogWrap({
    super.key,
    required this.child,
    this.dismissible = true,
  });
  final Widget child;
  final bool dismissible;

  @override
  State<GTNativeDialogWrap> createState() => _GTNativeDialogWrapState();
}

class _GTNativeDialogWrapState extends State<GTNativeDialogWrap> {
  @override
  Widget build(BuildContext context) {
    if (!widget.dismissible) {
      return Center(
        child: widget.child,
      );
    }
    return Stack(
      children: [
        Positioned.fill(
          child: GestureDetector(
            behavior: HitTestBehavior.translucent,
            onTap: () {
              if (Navigator.of(context).canPop()) {
                GTRouter.pop(context);
              } else {
                GTNativeDialogHelper.pop({});
              }
            },
            child: Container(
              color: const Color.fromRGBO(0, 0, 0, 0.8),
            ),
          ),
        ),
        Center(
          child: widget.child,
        )
      ],
    );
  }
}
